// e_cube.cpp
// Greg Dillon 4/13/11
// Based on e_cube.cc from QE Help file

#include "config.h"

#if BUILD_CUBE // compile this app

////////////////////////////////////////////////////////////////////////////////
// Header

#include "qec.h" // engine interface
#include <gl/glut.h>
#include <cyclone/cyclone.h>
using namespace cyclone;
////////////////////////////////////////////////////////////////////////////////
// Cube Parameters

// GHD 04/13/11; define XYZ positions of the 8 vertices on the cube
#define FRONT_TOP_LEFT  -1, 1, 1
#define FRONT_BOT_LEFT  -1,-1, 1
#define FRONT_BOT_RIGHT  1,-1, 1
#define FRONT_TOP_RIGHT  1, 1, 1

#define BACK_TOP_LEFT  -1, 1, -1
#define BACK_BOT_LEFT  -1,-1, -1
#define BACK_BOT_RIGHT  1,-1, -1
#define BACK_TOP_RIGHT  1, 1, -1

////////////////////////////////////////////////////////////////////////////////
// Functions

// JFL 07/29/06; main loop function added to qe
int gameMainLoop()
{
   
   Particle *p = new Particle();
   p->setPosition(1.0,1.0,1.0);

   // axes & grid
   qefnDrawGrid(10,1);
   qefnDrawAxes(1);

   // OpenGL calls to draw object
   glPolygonMode(GL_FRONT,GL_LINE); // draw wireframe polygons
   glColor3f(0,0,1); // set color to blue
   glColor3f(1,0.5,0); // set color to orange
   glCullFace(GL_BACK); // don't draw back faces
   glEnable(GL_CULL_FACE); // don't draw back faces

   // draw the faces of a 3D cube
   glBegin(GL_QUADS); // begin drawing OpenGL quads

   // draw face 1
   glVertex3f(FRONT_TOP_LEFT);
   glVertex3f(FRONT_BOT_LEFT);
   glVertex3f(FRONT_BOT_RIGHT);
   glVertex3f(FRONT_TOP_RIGHT);

   // GHD 04/13/11; added the other faces
   // draw face 2
   glVertex3f(FRONT_TOP_LEFT);
   glVertex3f(FRONT_TOP_RIGHT);
   glVertex3f(BACK_TOP_RIGHT);
   glVertex3f(BACK_TOP_LEFT);

   // draw face 3
   glVertex3f(BACK_TOP_LEFT);
   glVertex3f(BACK_TOP_RIGHT);
   glVertex3f(BACK_BOT_RIGHT);
   glVertex3f(BACK_BOT_LEFT);

   // draw face 4
   glVertex3f(FRONT_BOT_LEFT);
   glVertex3f(BACK_BOT_LEFT);
   glVertex3f(BACK_BOT_RIGHT);
   glVertex3f(FRONT_BOT_RIGHT);

   // draw face 5
   glVertex3f(FRONT_TOP_LEFT);
   glVertex3f(BACK_TOP_LEFT);
   glVertex3f(BACK_BOT_LEFT);
   glVertex3f(FRONT_BOT_LEFT);

   // draw face 6
   glVertex3f(FRONT_TOP_RIGHT);
   glVertex3f(FRONT_BOT_RIGHT);
   glVertex3f(BACK_BOT_RIGHT);
   glVertex3f(BACK_TOP_RIGHT);

   glEnd(); // finish drawing OpenGL primitives

   return 0;
} // gameMainLoop()

////////////////////////////////////////////////////////////////////////////////
// Main

// JFL 30 Jul 06
int qeMain(int argc,chr *argv[])
{
   // prints file, OpenGL version, and QE version
   qePrintf("%s / %s / %s\n",__FILE__,glGetString(GL_VERSION),qeVersion());

   // add a function object to the engine's processing list
   if(!qeObjAddFnc(gameMainLoop))
   {
      qePrintf("** qeObjAddFnc() failed\n");
   } // if

   // turn control over to the engine until the user closes the program
   qeForever();

   return 0;
} // qeMain()

#endif // compile this app
// EOF